﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using AutomatedMedicalDetection.model;
using System.Text.Json;

namespace AutomatedMedicalDetection.utils
{
    class Util
    {
        public static Dictionary<string, string> ReadDeviceInfoAsMap(string filePath)
        {
            try
            {
                string jsonString = File.ReadAllText(filePath);
                List<InstrumentConfiguration> devices = JsonSerializer.Deserialize<List<InstrumentConfiguration>>(jsonString);

                Dictionary<string, string> deviceMap = new Dictionary<string, string>();
                foreach (var device in devices)
                {
                    deviceMap[device.name.Trim()] = $"{device.ip}:{device.port}";
                }

                return deviceMap;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error reading JSON file: " + ex.Message);
                return null;
            }
        }
    }
}
